<template>
    <div>
        
        <h2>房价添加</h2>
        <table class="table table-bordered">
            <tr>
                <td algin="right">房型</td>
                <td><input type="text" v-model="state.htName" /></td>
            </tr>
            <tr>
                <td algin="right">房号</td>
                <td><input type="text" v-model="state.hnName" /></td>
            </tr>
            <tr>
                <td algin="right">房价</td>
                <td><input type="text" v-model="state.hmPrice" /></td>
            </tr>
            <tr>
                <td algin="right"></td>
                <td><input type="button" value="添加" @click="add" /></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
let router = useRouter()
let data = reactive({
    state: {
        htName: "",
        hnName: "",
        hmPrice: "",
    }
})
let { state } = toRefs(data)
const add = () => {
    if(state.value.htName==""){
        alert("房型不能为空")
        return
    }
    if(state.value.hnName==""){
        alert("房号不能为空")
        return
    }
    if(state.value.hmPrice==""){
        alert("房价不能为空")
        return
    }
    let obj = {
        htName: state.value.htName,
        hnName: state.value.hnName,
        hmPrice: state.value.hmPrice,
    }
    axios({
        url: '/api/HouseMoeny/AddHouseMoney',
        method: 'post',
        data: obj
    })
        .then(res => {
            console.log(res)
            if (res.data.data == 1) {
                alert("添加成功")
                router.push("/list")
            }
            else {
                alert("添加失败")
            }
        })
        .catch(err => {
            console.log(err)
        })
}
</script>

<style scoped></style>